<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>编辑</title>
		<link rel="stylesheet" type="text/css" href="../../plugins/layui/css/layui.css" />
		<link href="../../kitAdmin/css/app.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" type="text/css" href="../../plugins/select2/dist/css/select2.min.css"/>
		<style type="text/css">
			/* .select2-container{
				display:none;
			} */
			
			.layui-unselect.layui-form-select {
			    display: none;
			}
		</style>
	</head>

	<body>
		<div class='kit-table'>
			<div style='margin:10px'>
				
		<form class='layui-form' action='' lay-filter='form-edit'>
			<input type='hidden' name='studentId'  data-link='{:studentId}' />
			<input type='hidden' name='istrylisten'  data-link='{:istrylistend}' />
			<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>英文名</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:enName}' id='_enName' name='enName' class='layui-input'>
					</div>
				</div>
				<div class='layui-inline'>
					<label class='layui-form-label'>性别</label>
					<div class='layui-input-inline'>

						<select placeholder=''data-link='{:sex}' id='sex' name='sex' class='layui-input'></select>
					</div>
				</div>
			</div>
			<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>年龄</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:age}' id='_age' name='age' class='layui-input'>
					</div>
				</div>
				<div class='layui-inline'>
					<label class='layui-form-label'>QQ号</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:qq}' id='_qq' name='qq' class='layui-input'>
					</div>
				</div>
			</div>
			<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>微信号</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:wechat}' id='_wechat' name='wechat' class='layui-input'>
					</div>
				</div>
				<div class='layui-inline'>
					<label class='layui-form-label'>上课账号</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:zoomId}' id='_zoomId' name='zoomId' class='layui-input'>
					</div>
				</div>
			</div>
			<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>邮箱</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:email}' id='_email' name='email' class='layui-input'>
					</div>
				</div>
				<div class='layui-inline'>
					<label class='layui-form-label'>电话号</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:phone}' id='_phone' name='phone' class='layui-input'>
					</div>
				</div>
			</div>
			<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>地址</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:address}' id='_address' name='address' class='layui-input'>
					</div>
				</div>
				<div class='layui-inline'>
					<label class='layui-form-label'>英语水平</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:englishLevel}' id='_englishLevel' name='englishLevel' class='layui-input'>
					</div>
				</div>
			</div>
			<!--<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>需要加强</label>
					<div class='layui-input-inline'>
						<input type="checkbox"  name="englishAbility" title="听" value="听">
		                <input type="checkbox"  name="englishAbility" title="说" value="说">
		                <input type="checkbox"  name="englishAbility" title="读" value="读">
		                <input type="checkbox"  name="englishAbility" title="写" value="写">
					</div>
				</div>
				<div class='layui-inline'>
					<label class='layui-form-label'>老师名称</label>
					<div class='layui-input-inline'>

						<select  placeholder=''data-link='{:teacherId}' id='_teacherId' name='teacherId' class='layui-input'></select>
					</div>
				</div>
			</div>-->
			<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>负责人</label>
					<div class='layui-input-inline'>
						<select type='text' placeholder=''data-link='{:fuzerenId}' id='_fuzerenId' name='fuzerenId' class='layui-input'></select>
					</div>
				</div>
				<!--<div class='layui-inline'>
					<label class='layui-form-label'>推荐人</label>
					<div class='layui-input-inline'>
						<select  placeholder=''data-link='{:recommend}' id='_recommend' name='recommend' class='layui-input'></select>
					</div>
				</div>-->
			</div>
			<!--<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>课程</label>
					<div class='layui-input-inline'>
						<select  placeholder='' lay-filter="_cource" data-link='{:cource}' id='_cource' name='cource' class='layui-input'></select>
					</div>
				</div>
				<div class='layui-inline'>
					<label class='layui-form-label'>课程等级</label>
					<div class='layui-input-inline'  >
						<select placeholder='' lay-filter="_courceLevel" data-link='{:courceLevel}' id='_courceLevel' name='courceLevel' class='layui-input'>
							<option value='请选择' selected="true">请选择</option>
						</select>
					</div>
				</div>
			</div>-->
			<!--<div class='layui-form-item'>
				<div class="layui-form-item">
					<label class="layui-form-label">试听时间</label>
				    <div class="layui-input-inline" style="margin-right: 0px; width: 146px;">
				      	<input type='text' placeholder=''data-link='{:auditionTime}' id='_auditionTime' name='auditionTime' class='layui-input'>
					</div>
				    <span class="input-group-btn">
				        <a style="height: 38px;line-height:38px;" class="layui-btn layui-btn-sm" type="button" onclick="setaudiotime()">添加</a>
			      	</span>
				</div>
			</div>-->
			<!--<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>试听次数</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:auditionCount}' id='_auditionCount' name='auditionCount' class='layui-input'>
					</div>
				</div>
			</div>	
			<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>是否喜欢家庭作业</label>
					<div class='layui-input-block'>
						<input type="radio" data-link='{:homeworkLike}' name="homeworkLike" value="0" title="否"/>
					 	<input type="radio" data-link='{:homeworkLike}' name="homeworkLike" value="1" title="是"/>
					</div>
				</div>
			</div>-->
			<div class='layui-form-item'>
				<div class='layui-inline'>
					<label class='layui-form-label'>备注</label>
					<div class='layui-input-inline'>
						<input type='text' placeholder=''data-link='{:comments}' id='_comments' name='comments' class='layui-input'>
					</div>
				</div>
			</div>
		  
		</form>
			</div>
		</div>
		<script src="../../common/js/jquery.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/base.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../plugins/jsviews/jsviews.js" type="text/javascript"></script>
		<script src="../../plugins/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../plugins/select2/dist/js/select2.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var uid = getQueryVariable('studentId');
			
			var entity; 
			
			var callback_save=function(){
				console.log($('.layui-form').serialize());
				return $('.layui-form').serialize();
			}
			
			function bindFormData(){
				if(uid){
					$.ajax({
						url:baseUrl+'/students/'+uid,
						type:'get',
						//async:false,
						success:function(data){
							entity=data.data;
							bindEnglishAbility();
							bindLessonLevelSelect2();
							$.link(true, ".kit-table", data.data);
							$('select').select2().change();
							//console.log(data.data.istrylisten);
							
							$('input[name="istrylisten"]').val("是");
						},
						error:function(){
							parent.layer.alert('系统或网络错误！');
						}
					});
				}
			}
			
			
			$(document).ready(function(){

				bindFormData();
				bindSexSelect2();
//				bindTeacherSelect2();
//				bindRecommendSelect2();
				bindFuzerenSelect2();
//				bindLessonSelect2();
				
				
				
				
				
				//select2通过模板绑定值以后不会自动刷新，需手动刷新一下；
				//注意，layui的select和select2用的不是一个控件，如果使用layui的select下面的这句可以注释掉
				//如果是select2，这下面的需要保留
				$('select').select2().change();
				
				$('#_cource').on("select2:select",function(){
					$('#_courceLevel').empty();
					$.ajax({
						url : baseUrl+"/levels/select2/" + $(this).val(),
						async : false,
						dataType : 'json',
						success : function(result) {
							
							$('#_courceLevel').select2({
								data : result
							});
							
						}
					});
				});
				layui.use(['form'], function(){
					/* var form = layui.form;
					form.on('submit',function(){
						
					}) */
				});
			});

			function bindLessonLevelSelect2(data) {
				//console.log(entity);
				var courceData = [];
				$.ajax({
					type : "get",
					url : baseUrl+'/levels/select2/'+entity.cource,
					async : false,
					success : function(data) {
						//console.log(data);
						courceData = data;
						courceData.unshift({
							id : '请选择',
							text : '请选择'
						});
					}
				});

				$('#_courceLevel').select2({
					data : courceData
				});
			}

			function bindLessonSelect2() {
				var courceData = [];
				$.ajax({
					type : "get",
					url :baseUrl+ '/lessons/select2',
					async : false,
					success : function(data) {
						//console.log(data);
						courceData = data;
						courceData.unshift({
							id : '请选择',
							text : '请选择'
						});
					}
				});

				$('#_cource').select2({
					data : courceData
				});

			}

			function bindEnglishAbility() {
				var functional = entity.englishAbility;
				var groupCheckbox = $("input[name='englishAbility']");
				console.log('// 2018-9-25 chenbin: EnglishAbility:', functional);
				if (functional != null && functional != '') {
					// 2018-9-25 chenbin: 解决原数据无法绑定问题
					for (i = 0; i < groupCheckbox.length; i++) {
						var val = groupCheckbox[i].value;
	 					if (functional.split(',').indexOf(val) != -1) {
	 						groupCheckbox[i].checked = true;
	 					}
					}
				}
				
			}

			function bindSexSelect2() {
				var sexData = [ {
					id : '请选择',
					text : '请选择'
				}, {
					id : '男',
					text : '男'
				}, {
					id : '女',
					text : '女'
				} ];

				$('#sex').select2({
					data : sexData
				});
			}

			function bindRecommendSelect2() {
				var courceData = [];
				$.ajax({
					type : "get",
					url :baseUrl+ '/students/select2',
					async : false,
					success : function(data) {
						//console.log(data);
						courceData = data;
						courceData.unshift({
							id : '请选择',
							text : '请选择'
						});
					}
				});

				$('#_recommend').select2({
					data : courceData
				});
			}
			function bindFuzerenSelect2() {
				var courceData = [];
				$.ajax({
					type : "get",
					url : baseUrl+'/admins/select2',
					async : false,
					success : function(data) {
						//console.log(data);
						courceData = data;
						courceData.unshift({
							id : '请选择',
							text : '请选择'
						});
					}
				});

				$('#_fuzerenId').select2({
					data : courceData
				});
			}
			function bindTeacherSelect2() {
				var courceData = [];
				$.ajax({
					type : "get",
					url :baseUrl+ '/teachers/select2',
					async : false,
					success : function(data) {
						//console.log(data);
						courceData = data;
						courceData.unshift({
							id : '请选择',
							text : '请选择'
						});
					}
				});

				$('#_teacherId').select2({
					data : courceData
				});
			}
			
			function setaudiotime(){
				var teacherid=$("#_teacherId").val();
				if(teacherid=="请选择"){
					alert("请选择老师");
					return;
				}
				var studentid=uid;
				console.log(uid);
				parent.layer.open({
					id:teacherid+'info',
					maxmin: true,
					type: 2,
					area: modalArea,
					content: './views/Period_Used.html?techerid='+teacherid+'&studentid='+uid,
					btn: ['保存', '取消'],
					yes: function(index, layero) {
						var data = $(layero).find("iframe")[0].contentWindow.callback_save();
						console.log(layero);
						$.ajax({
							url:baseUrl+ '/teacherPeriods/periodUsed/save/'+data[0],
							type: 'POST',
							data: data[1],//,teacherId:'1245745'
							dataType:"json",      
			           		contentType:"application/json",
							success: function(data) {
								/* alert(data.data); */
								alert("保存成功");
							}
						});
					},
					btn2: function(index, layero) {
						//按钮【按钮二】的回调
						console.log(layero);
						//return false 开启该代码可禁止点击该按钮关闭
					}
				});
			}
			
			
		</script>
	</body>

</html>
